﻿using EntityModels.Entities;
using Microsoft.EntityFrameworkCore;

namespace EntityModels.DbContexts
{
    /// <summary>
    /// 序列
    /// </summary>
    public class SequenceForEntityDbContext : DbContext
    {
        public DbSet<SequenceEntity1> SequenceEntity1s => Set<SequenceEntity1>();

        public DbSet<SequenceEntity2> SequenceEntity2s => Set<SequenceEntity2>();

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasSequence<int>("SequenceNumbers", schema: "shared")
                .StartsAt(1).IncrementsBy(2);

            modelBuilder.Entity<SequenceEntity1>()
                .Property(s => s.Sequence)
                .HasDefaultValueSql("next value for shared.SequenceNumbers");

            modelBuilder.Entity<SequenceEntity2>()
                .Property(s => s.Sequence)
                .HasDefaultValueSql("next value for shared.SequenceNumbers");

        }

    }
}
